package com.qujia.station.service.impl;

import com.qujia.station.domain.PayWay;
import com.qujia.station.domain.PayWayStationBetween;
import com.qujia.station.mapper.PayStationBetweenMapper;
import com.qujia.station.mapper.PayWayMapper;
import com.qujia.station.service.IPayStationBetweenService;
import com.qujia.station.service.IPayWayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 油站信息Service业务层处理
 * 
 * @author qujia
 * @date 2020-12-08
 */
@Service
public class PayStationBetweenServiceImpl implements IPayStationBetweenService
{
    @Autowired
    private PayStationBetweenMapper payStationBetweenMapper;
    /**
     * 查询支付方式和油站的中间报表信息
     *
     * @param payStationId 中间表id信息
     * @return 油罐信息
     */
    public PayWayStationBetween selectPayWayStationBetweenById(Long payStationId){
        return  payStationBetweenMapper.selectPayWayStationBetweenById(payStationId);
    }


    /**
     * 查询中间表信息信息列表
     *
     * @param payWayStationBetween 中间表信息信息
     * @return 中间表信息集合
     */
    public List<PayWayStationBetween> selectPayWayStationBetweenList(PayWayStationBetween payWayStationBetween){
        return  payStationBetweenMapper.selectPayWayStationBetweenList(payWayStationBetween);
    }
    /**
     * 批量新增关联支付方式
     * *
     * @param payWayStationBetweenList 中间表信息
     * @return 结果
     */
    @Transactional
    public int addPayWayStationBetweenList(List<PayWayStationBetween> payWayStationBetweenList)  throws Exception{
        int i=0;
        for( PayWayStationBetween payWayStationBetween:payWayStationBetweenList){
            i=insertPayWayStationBetween(payWayStationBetween);
        }
        return i;
    }

    /**
     * 批量新增关联支付方式
     * *
     * @param payWayStationBetweenList 中间表信息
     * @return 结果
     */
    @Transactional
    public int insertAutoPayWayOver(List<PayWayStationBetween> payWayStationBetweenList)  throws Exception{
        int i=0;
        for( PayWayStationBetween payWayStationBetween:payWayStationBetweenList){
            i=insertAutoPayWayOver(payWayStationBetween);
        }
        return i;
    }


    /**
     * 通过定时器，新增不同的支付方式
     * *
     * @param payWayStationBetweenList   当前支付方式的集合，要删除的stationId
     * @return 结果
     */
    public int timingAddPayWayStationBetweenList(List<PayWayStationBetween> payWayStationBetweenList,Long stationId)  throws Exception{
        payStationBetweenMapper.deletePayWayStationBetweenByStationId(stationId);
        int i=0;
        for( PayWayStationBetween payWayStationBetween:payWayStationBetweenList){
            i=insertPayWayStationBetween(payWayStationBetween);
        }
        return i;
    }


    /**
     * 新增中间表信息
     *
     * @param payWayStationBetween 中间表信息
     * @return 结果
     */
    public int insertPayWayStationBetween(PayWayStationBetween payWayStationBetween){
        return  payStationBetweenMapper.insertPayWayStationBetween(payWayStationBetween);
    }

    /**
     * 新增中间表信息
     *
     * @param payWayStationBetween 中间表信息
     * @return 结果
     */
    public int insertAutoPayWayOver(PayWayStationBetween payWayStationBetween){
        return  payStationBetweenMapper.insertAutoPayWayOver(payWayStationBetween);
    }

    /**
     * 修改中间表信息
     *
     * @param payWayStationBetween 中间表信息
     * @return 结果
     */
    public int updatePayWayStationBetween(PayWayStationBetween payWayStationBetween){
        return  payStationBetweenMapper.updatePayWayStationBetween(payWayStationBetween);
    }

    /**
     * 删除中间表信息
     *
     * @param payStationId 中间表ID
     * @return 结果
     */
    @CacheEvict(value = { "EnterpriseServiceImpl_selectStaPayWay"},
            key="'**'",
            condition = "#root.args[0] != null"
    )
    public int deletePayWayStationBetweenById(Long payStationId){
        return  payStationBetweenMapper.deletePayWayStationBetweenById(payStationId);
    }

    /**
     * 删除中间表信息
     *
     * @param payStationId 中间表ID
     * @return 结果
     */
    @CacheEvict(value = { "EnterpriseServiceImpl_selectStaPayWay"},
            key="'**'",
            condition = "#root.args[0] != null"
    )
    public int deleteAutoPayWayOver(Long stationId){
        return  payStationBetweenMapper.deleteAutoPayWayOver(stationId);
    }


    /**
     * 批量删除中间表信息
     *
     * @param payStationIds 需要删除的数据ID
     * @return 结果
     */
    public int deletePayWayStationBetweenByIds(Long[] payStationIds){
        return  payStationBetweenMapper.deletePayWayStationBetweenByIds(payStationIds);
    }

    /**
     * 通过油站id批量删除支付方式表
     *
     * @param stationId 需要删除的数据ID
     * @return 结果
     */
    public int deletePayWayStationBetweenBySationId(Long stationId){
        return  payStationBetweenMapper.deletePayWayStationBetweenByStationId(stationId);
    }

}
